using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Viper;

namespace Viper.Opcodes
{
    public class begin_fault : Instruction
    {
		string sym;
        public begin_fault(string symbol)
        {
			sym = symbol;
			this.Mnemonic = "begin_try";
			this.Operand = sym;
            this.Bytecode = new byte[6];
        }
		public override void Relocate (ref List<Symbol> symbols)
		{
			int rel = 0;
			foreach(Symbol s in symbols)
			{
				if(s.Name == sym)
				{
					rel = (int)(s.Address - ((int)(this.Address) + 6));
					break;
				}
			}
			byte[] val = System.BitConverter.GetBytes(rel);
			this.Bytecode = new byte[]{0x50,4,val[0],val[1],val[2],val[3]};
		}
    }
}